# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Contributor: John Regan <john@jrjrtech.com>
# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ejabberd
pkgver=24.02
pkgrel=0

_base64url=1.0.1
_cache_tab=1.0.30
_eimp=1.0.22
_ejabberd_po=fd0e059de4c0772de37339a0a95f9a474d107b59
_epam=1.0.14
_eredis=1.2.0
_esip=1.0.52
_ezlib=1.0.12
_fast_tls=1.1.19
_fast_xml=1.1.51
_fast_yaml=1.0.36
_idna=6.0.0
_jiffy=1.1.1
_jose=1.11.5
_luerl=1.1.1
_mqtree=1.0.16
_p1_acme=1.0.22
_p1_mysql=1.0.23
_p1_oauth2=0.6.14
_p1_pgsql=1.1.25
_p1_utils=1.0.25
_pkix=1.0.9
_sqlite3=1.1.14
_stringprep=1.0.29
_stun=1.2.12
_unicode_util_compat=0.4.1
_xmpp=1.8.1
_yconf=1.0.15

pkgdesc="An erlang jabber server"
url="https://www.ejabberd.im/"
arch="all"
license="GPL-2.0-or-later"
depends="
	erlang
	elixir
	"
makedepends="
	autoconf
	automake
	erlang-dev
	expat-dev
	gd-dev
	heimdal-dev
	linux-pam-dev
	openssl-dev>3
	rebar3
	sqlite-dev
	yaml-dev
	zlib-dev
	"
pkgusers="ejabberd"
pkggroups="ejabberd"
install="$pkgname.pre-install"
options="!check" # test suite requires all kinds of services running
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/processone/ejabberd/archive/$pkgver.tar.gz
	base64url-$_base64url.tar.gz::https://github.com/dvv/base64url/archive/refs/tags/$_base64url.tar.gz
	cache_tab-$_cache_tab.tar.gz::https://github.com/processone/cache_tab/archive/refs/tags/$_cache_tab.tar.gz
	eimp-$_eimp.tar.gz::https://github.com/processone/eimp/archive/refs/tags/$_eimp.tar.gz
	ejabberd_po-$_ejabberd_po.tar.gz::https://github.com/processone/ejabberd-po/archive/$_ejabberd_po.tar.gz
	epam-$_epam.tar.gz::https://github.com/processone/epam/archive/refs/tags/$_epam.tar.gz
	eredis-$_eredis.tar.gz::https://github.com/wooga/eredis/archive/refs/tags/v$_eredis.tar.gz
	esip-$_esip.tar.gz::https://github.com/processone/esip/archive/refs/tags/$_esip.tar.gz
	ezlib-$_ezlib.tar.gz::https://github.com/processone/ezlib/archive/refs/tags/$_ezlib.tar.gz
	fast_tls-$_fast_tls.tar.gz::https://github.com/processone/fast_tls/archive/refs/tags/$_fast_tls.tar.gz
	fast_xml-$_fast_xml.tar.gz::https://github.com/processone/fast_xml/archive/refs/tags/$_fast_xml.tar.gz
	fast_yaml-$_fast_yaml.tar.gz::https://github.com/processone/fast_yaml/archive/refs/tags/$_fast_yaml.tar.gz
	idna-$_idna.tar.gz::https://github.com/benoitc/erlang-idna/archive/refs/tags/$_idna.tar.gz
	jiffy-$_jiffy.tar.gz::https://github.com/davisp/jiffy/archive/refs/tags/$_jiffy.tar.gz
	jose-$_jose.tar.gz::https://github.com/potatosalad/erlang-jose/archive/refs/tags/$_jose.tar.gz
	luerl-$_luerl.tar.gz::https://github.com/rvirding/luerl/archive/refs/tags/v$_luerl.tar.gz
	mqtree-$_mqtree.tar.gz::https://github.com/processone/mqtree/archive/refs/tags/$_mqtree.tar.gz
	p1_acme-$_p1_acme.tar.gz::https://github.com/processone/p1_acme/archive/refs/tags/$_p1_acme.tar.gz
	p1_mysql-$_p1_mysql.tar.gz::https://github.com/processone/p1_mysql/archive/refs/tags/$_p1_mysql.tar.gz
	p1_oauth2-$_p1_oauth2.tar.gz::https://github.com/processone/p1_oauth2/archive/refs/tags/$_p1_oauth2.tar.gz
	p1_pgsql-$_p1_pgsql.tar.gz::https://github.com/processone/p1_pgsql/archive/refs/tags/$_p1_pgsql.tar.gz
	p1_utils-$_p1_utils.tar.gz::https://github.com/processone/p1_utils/archive/refs/tags/$_p1_utils.tar.gz
	pkix-$_pkix.tar.gz::https://github.com/processone/pkix/archive/refs/tags/$_pkix.tar.gz
	sqlite3-$_sqlite3.tar.gz::https://github.com/processone/erlang-sqlite3/archive/refs/tags/$_sqlite3.tar.gz
	stringprep-$_stringprep.tar.gz::https://github.com/processone/stringprep/archive/refs/tags/$_stringprep.tar.gz
	stun-$_stun.tar.gz::https://github.com/processone/stun/archive/refs/tags/$_stun.tar.gz
	unicode_util_compat-$_unicode_util_compat.tar.gz::https://github.com/benoitc/unicode_util_compat/archive/refs/tags/$_unicode_util_compat.tar.gz
	xmpp-$_xmpp.tar.gz::https://github.com/processone/xmpp/archive/refs/tags/$_xmpp.tar.gz
	yconf-$_yconf.tar.gz::https://github.com/processone/yconf/archive/refs/tags/$_yconf.tar.gz

	$pkgname.initd
	$pkgname.logrotate
	$pkgname.confd
	"

export HEX_HOME="${HEX_HOME:-"$srcdir/hex"}"
export MIX_HOME="${MIX_HOME:-"$srcdir/mix"}"
export MIX_ARCHIVES="${MIX_ARCHIVES:-"$srcdir/mix/archives"}"

prepare() {
	mkdir deps
	for i in \
	base64url-$_base64url \
	cache_tab-$_cache_tab \
	eimp-$_eimp \
	epam-$_epam \
	eredis-$_eredis \
	esip-$_esip \
	ezlib-$_ezlib \
	fast_tls-$_fast_tls \
	fast_xml-$_fast_xml \
	fast_yaml-$_fast_yaml \
	jiffy-$_jiffy \
	luerl-$_luerl \
	mqtree-$_mqtree \
	p1_acme-$_p1_acme \
	p1_mysql-$_p1_mysql \
	p1_oauth2-$_p1_oauth2 \
	p1_pgsql-$_p1_pgsql \
	p1_utils-$_p1_utils \
	pkix-$_pkix \
	stringprep-$_stringprep \
	stun-$_stun \
	unicode_util_compat-$_unicode_util_compat \
	xmpp-$_xmpp \
	yconf-$_yconf; do
		mv "$srcdir"/"$i" "$builddir"/deps/${i%-*}
	done
	mv "$srcdir"/ejabberd-po-$_ejabberd_po "$builddir"/deps/ejabberd_po
	mv "$srcdir"/erlang-sqlite3-$_sqlite3 "$builddir"/deps/sqlite3
	mv "$srcdir"/erlang-idna-$_idna "$builddir"/deps/idna
	mv "$srcdir"/erlang-jose-$_jose  "$builddir"/deps/jose

	mix local.hex --force
	mix local.rebar --force rebar3 /usr/bin/rebar3

	default_prepare
	GIT_DIR=. sh ./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--sbindir=/usr/sbin \
		--libdir=/usr/lib/ejabberd \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-rebar=rebar3 \
		--disable-tools \
		--enable-user=ejabberd \
		--enable-group=ejabberd \
		--enable-all
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 tools/captcha* \
		-t "$pkgdir"/usr/share/doc/$pkgname/examples
	install -Dm644 tools/ejabberdctl.bc \
		"$pkgdir"/usr/share/bash-completion/completions/ejabberdctl

	install -d "$pkgdir"/var/spool/$pkgname
	install -d "$pkgdir"/var/lib/$pkgname
	install -D -m0644 "$srcdir"/$pkgname.logrotate \
		"$pkgdir"/etc/logrotate.d/$pkgname
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	chown -R ejabberd.ejabberd "$pkgdir"/var/log/ejabberd
	chown -R ejabberd.ejabberd "$pkgdir"/var/spool/ejabberd
	chown -R ejabberd.ejabberd "$pkgdir"/var/lib/ejabberd
	chgrp ejabberd "$pkgdir"/etc/ejabberd/ejabberd.yml \
		"$pkgdir"/etc/ejabberd/ejabberdctl.cfg "$pkgdir"/etc/ejabberd

	cd "$pkgdir"/usr/lib/ejabberd/ejabberd-$pkgver/priv/bin/
	rm -vf captcha.sh
	ln -vsf ../../../*/priv/bin/* .
}

sha512sums="
43dcf1c0f1a2a0390de9edfa24705be6b5bcfdc83b307c175effeae043b4a67dd00c4930c5e43fda98c7c3e0060fac7198313cd27b7962a8997e006ef255df0c  ejabberd-24.02.tar.gz
7398dc99078053b6e0544eb8ca93e9616549493c02245084c220ec854f429139dcaba38dd522858dd74b95067979a3ec4378eb3abd5f6d1662af27687381c738  base64url-1.0.1.tar.gz
bc8aaacea404d8a8b9a8fb14bc1eec9ec0c07ba4fac910287f448be66b0b3475b3913297dfce8d9de9fc208d9eb413dd8bf154cd1bd6edf86ee40100629e4553  cache_tab-1.0.30.tar.gz
5426df9a00d5b614ebb236729e2b397d5e72e12e68cbed32550a074b1b86557e1dee6585b917166e5ebf2fc41297329574c181471885638236c82a66a29d2232  eimp-1.0.22.tar.gz
c5eb9b8a1354357058d0fdf8cd36d6586703f23bf8aed4a354f4290c62db2864ddccb8c403c785541e2bbe4d0e45318092e4b25b55b60c052b6e7f2945080879  ejabberd_po-fd0e059de4c0772de37339a0a95f9a474d107b59.tar.gz
a8ff1e6095ad6f2cdf8a9766a7d846377e6ac5659851078a67a80595710fbd1552f900f0b4cad0baa54d63d3fbbe6009371f3a51dcaffe95c17565c0f7177678  epam-1.0.14.tar.gz
c72ae291389e47d1ac4c1de69dccb6121f4f9195283665d490904226b2ea15cb7671b48bb08db507a5e62c6bced62d890a9ecb9752da6e0aad24a28da137907c  eredis-1.2.0.tar.gz
0d8af52674d0313121ea0c4b006549190ab860467fd85a5d59df5c19c4448337f055c57c1adb958fc2d22704bef9de6bc766efba64a80a7fd157c0a2a019ce3b  esip-1.0.52.tar.gz
950a76ef6714882909c8c03cb0c21f246fd04bb42b44496b8865a96da54544fad17b2e3f54ef0b744ae32a1b9930f32c5fbcd526833f3736e8e5087483e61233  ezlib-1.0.12.tar.gz
ca1c1763c600d6e1b87a231728e9c836d23064c17c48c80efdedec0de7677305a095b61ecdf5a5b1b33cc8dbeec00cdc3242f08288bcd074ad57e212cd55d213  fast_tls-1.1.19.tar.gz
ef442120b754786548f5ea20880a7ab155105aa40d27ae547a07dbc3892e6b87df0e8e41349bd2f09898fa3664cb72410074a07f67084d3496f0bf0f0fd920d9  fast_xml-1.1.51.tar.gz
f479060bc5c37c5a86dad9b96b4d094edc5a0c41414e1c8f3c1b92553b9169f0990fc9a515f3dc199ed20147e84ede7f3e9956bce7236446bb932404899be1c4  fast_yaml-1.0.36.tar.gz
59f8996199f7e3391b1da1b8fb1ebb70e442838eab1f26af9a8a8545f3e1b9f72f0afd65108272a51d846b34e0e8abe9623f10c89156ebca3d87b6b3eb63a066  idna-6.0.0.tar.gz
cfa36d77285e53ccce852640a4c780f2c29ad33c7352e3a5b69fec431d6684bac4bf5ac323379a8bb1d1289afa23b6f73d4d5ecf1b025791fd84198d4c066910  jiffy-1.1.1.tar.gz
2d1a293dbe63ce7dc32a07929f30580f47db468e540bc28433971a362feb3b19ef65caf11d74ddd7cd80a5be80e22ab4d0752a9bf248ac60f8f05c69e51ba1a0  jose-1.11.5.tar.gz
2ffe2fca97204d49d113c5741aa608e985556b9b8474d96f95699629e7cb2320ae0e2d60acaef30ec69e075c8ef55fec8077b45304f9ba2dc62864a467eea52a  luerl-1.1.1.tar.gz
435b4b3679827e7e2e9bf0f439c7f734a61095b576a8a5d461efe9bda31698a07171e1a13fa0378323b8d2713365ad4d4c4a06e4e75e467758b416aa08387113  mqtree-1.0.16.tar.gz
b632e8e1f944675681bdb5345c4eabc8c13ea9e356244bc559e2c3d037e0897488699b8e054313693961aba41024141f6ecaa99e843f0651775f45960a438ebb  p1_acme-1.0.22.tar.gz
ad098641518e5ca264321d54a1571cb74234115889c237d538a313bf05db85fabe78a97ea971f0e1335dcda0e957c9fdf4a3a2e15569327acdad25a079f74337  p1_mysql-1.0.23.tar.gz
cda660e2401a951864d365017f508c2e317794a7aec7ee3aae96d476764252b56de516b31ca73da00c4a9ceefeefe22d673b4659e988179aeb9bb3eef0bf66ed  p1_oauth2-0.6.14.tar.gz
78151d55cf75a11e1ffb8d6cccced7885c810a1c1972c9cdb42b2bc3147c9d1311e2247e08dd899632c32fa8e1d9adaff6ee09249a125ecd7ac00d305ed02b17  p1_pgsql-1.1.25.tar.gz
e96bcd309dfaf3f80de573b7ad1b7281ee0cb97b0b91f92a5a9c5b5ccc969dce4d6b1adbaef9ff33bf9deb0da8e6b1738fbe3f69235b51a0069e0fda72a16d74  p1_utils-1.0.25.tar.gz
bd428814421effdc74c418a376b44716f4f79095550dd1b8431bfb51e8d26262015be0dda7948a9b8f9fc60a0cd0d12289161c8b497134f6413fd1e1efb886ba  pkix-1.0.9.tar.gz
afe3fc31e53ccaf509c403b5c830e55c94fb2c44471b0a94126ee717dd98ad042f6b56c62a3a071ee920550be291b33d393a72b43253e137b43545623e9292f8  sqlite3-1.1.14.tar.gz
53b24c166d9328efab8e01b3e7ee7df3d66d240a6ac95f5338d0237ae4e6db20a4f53b487d632cbe6ae46c5f2c62001f7afb77172b27840a824944e51e08ef56  stringprep-1.0.29.tar.gz
43557481cde2604903ea6d692381a608fe5c35e24cd28c989dddb83023ad6ec3938c48853b58c99b153c6298da6ce086eaa5776987e21b06d0ed402167741c45  stun-1.2.12.tar.gz
ee5bc1600ea00ad9c1d9f1565d04d073dd357c6f69c0728e770e17f7e4f1a07c2d2883d05e344d33dd7fe62e310ae4b86e4a05998e4830fedc6b895653993532  unicode_util_compat-0.4.1.tar.gz
fc53c0480e8547080cdd1c3fa3ba13736a511e2a61a14a69d2e92249d0aa127c59450b37c0b45c585ccae9fe19cf7070c6b61bad1e214a48d830935424f049cc  xmpp-1.8.1.tar.gz
9ee2022c4612253597580f27db58072c545f182f9c615c7137e9d42ac84cd473a598719e7ba3de654b72c5789f237448cc37fddeb863103b290d22483af3f313  yconf-1.0.15.tar.gz
18fb890794be6b0e63960af80a39a97b8c70a6c0ab9a91a95d0f623257e38f5a43c012430ccf871038fc440d06720c573821b485a94191bd73e3924e670683c5  ejabberd.initd
47fd2cfd9177c4e978a9799a153ba74392a9891822221af8194686a40f6bf01f38644833e1e1f5416c6357e0bfb7ca3dae96f55a4fcd7cd629ec798d85a72807  ejabberd.logrotate
96a571c0ab2be366e931bda423a61ef920cbaba2107e61ddbc501472ce3efe2804418cc6579c99310b902a9a99aaecb9284cf2420c071dbca2f670efb4034135  ejabberd.confd
"
